using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Documents;
using System.Windows;
using System.Windows.Media;

namespace WozLib.UI.Ink.Adorners
{
  public class LinePreviewAdorner : Adorner
  {

    public Point EndPoint
    {
      get { return _EndPoint; }
      set { _EndPoint = value; }
    } private Point _EndPoint;

    public Point StartPoint
    {
      get { return _StartPoint; }
      set { _StartPoint = value; }
    } private Point _StartPoint;


    // Be sure to call the base class constructor.
    public LinePreviewAdorner(UIElement adornedElement, Point startPoint, Point endPoint)
      : base(adornedElement)
    {
      StartPoint = startPoint;
      EndPoint = endPoint;
    }

    // A common way to implement an adorner's rendering behavior is to override the OnRender
    // method, which is called by the layout subsystem as part of a rendering pass.
    protected override void OnRender(DrawingContext drawingContext)
    {
      // Get a rectangle that represents the desired size of the rendered element
      // after the rendering pass.  This will be used to draw at the corners of the 
      // adorned element.
      Rect adornedElementRect = new Rect(this.AdornedElement.DesiredSize);

      // Some arbitrary drawing implements.
      SolidColorBrush renderBrush = new SolidColorBrush(Colors.Green);
      renderBrush.Opacity = 0.2;
      Pen renderPen = new Pen(new SolidColorBrush(Colors.Navy), 1.5);
      double renderRadius = 5.0;

      if (adornedElementRect.Contains(EndPoint))
      {

        // Just draw a circle at each corner.
        drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Black), 1), StartPoint, EndPoint);
        drawingContext.DrawEllipse(renderBrush, renderPen, StartPoint, renderRadius, renderRadius);
        drawingContext.DrawEllipse(renderBrush, renderPen, EndPoint, renderRadius, renderRadius);
      }
      else
      {
        // Just draw a circle at each corner.
        drawingContext.DrawLine(new Pen(new SolidColorBrush(Colors.Red), 1), StartPoint, EndPoint);
        drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), renderPen, StartPoint, renderRadius, renderRadius);
        drawingContext.DrawEllipse(new SolidColorBrush(Colors.Red), renderPen, EndPoint, renderRadius, renderRadius);
      }
      
    }
  }
}

